feat(cli): add export command to generate desired-state YAML from current state#1731
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds export support to the reconcile framework, implements platform user export, and wires a new ChangesReconcile export feature
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 75607dba-a629-489d-b90a-5de555cb5f68
📒 Files selected for processing (5)
cmd/reconcile.gointernal/reconcile/platformuser_reconciler.gointernal/reconcile/platformuser_reconciler_test.gointernal/reconcile/reconcile.gointernal/reconcile/reconcile_test.go
Coverage Report for CI Build 29316383996Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage increased (+0.1%) to 44.984%Details
Uncovered Changes
Coverage Regressions230 previously-covered lines in 8 files lost coverage.
Coverage Stats
💛 - Coveralls |
2ca9edd to
d553b7f
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 025c0faa-f5bc-4b12-bf33-7bcc3ee2fbaa
📒 Files selected for processing (7)
cmd/apply.gocmd/get.gocmd/root.gointernal/reconcile/platformuser_reconciler.gointernal/reconcile/platformuser_reconciler_test.gointernal/reconcile/reconcile.gointernal/reconcile/reconcile_test.go
✅ Files skipped from review due to trivial changes (1)
- internal/reconcile/reconcile.go
🚧 Files skipped from review as they are similar to previous changes (3)
- internal/reconcile/platformuser_reconciler.go
- internal/reconcile/platformuser_reconciler_test.go
- internal/reconcile/reconcile_test.go
d553b7f to
987ae62
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
cmd/export.go (1)
51-56: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick winNarrow output file permissions for exported PII.
The exported document contains per-principal emails; writing with
0o644leaves it world-readable. Matches an already-flagged concern on a prior commit of this file.🔒 Proposed fix
- return os.WriteFile(output, out, 0o644) + return os.WriteFile(output, out, 0o600)
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4ef1ccea-dab3-45ac-8fb9-8f03784960e8
📒 Files selected for processing (7)
cmd/export.gocmd/reconcile.gocmd/root.gointernal/reconcile/platformuser_reconciler.gointernal/reconcile/platformuser_reconciler_test.gointernal/reconcile/reconcile.gointernal/reconcile/reconcile_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
- internal/reconcile/reconcile_test.go
- internal/reconcile/reconcile.go
- internal/reconcile/platformuser_reconciler.go
- internal/reconcile/platformuser_reconciler_test.go
987ae62 to
12fc9a5
Compare
…xport in CLI reference
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cmd/export.go (1)
47-50: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueSkip the byte→string conversion.
string(out)allocates a copy just to hand it back toFprint. Writing the bytes directly avoids the extra allocation.♻️ Proposed simplification
- // cobra's cmd.Print falls back to stderr; the document must go to - // stdout so redirecting to a file works. - _, err = fmt.Fprint(cmd.OutOrStdout(), string(out)) - return err + // cobra's cmd.Print falls back to stderr; the document must go to + // stdout so redirecting to a file works. + _, err = cmd.OutOrStdout().Write(out) + return err
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a3d55fcb-3ab0-46c1-9eb0-a4adceb02a73
📒 Files selected for processing (9)
cmd/export.gocmd/export_test.gocmd/reconcile.gocmd/root.godocs/content/docs/reference/cli.mdxinternal/reconcile/platformuser_reconciler.gointernal/reconcile/platformuser_reconciler_test.gointernal/reconcile/reconcile.gointernal/reconcile/reconcile_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
- internal/reconcile/reconcile_test.go
- internal/reconcile/platformuser_reconciler_test.go
- internal/reconcile/platformuser_reconciler.go
- internal/reconcile/reconcile.go
whoAbhishekSah
left a comment
There was a problem hiding this comment.
Future Improvement suggestion: CLI filter for type supporting user and serviceuser.
|
From the RFC review (#1751): export must be required for every kind, per rule 9 there. This PR describes |
|
Two more changes landed here from the RFC review (#1751): documents now carry |
Review noteAn independent pass flagged |
What
Adds
frontier export <kind>, a top-level sibling offrontier reconcile. It reads the current state of one kind from the server through the admin API and prints it as a desired-state YAML document, the same formatreconcilereads. Output goes to stdout only — redirect it to save a file. YAML is the only format.The
reconcilecommand is unchanged. The kind argument is case-insensitive and accepts a plural, soplatformusersfindsPlatformUser. An unknown kind lists the available ones.Both
reconcileandexportare now documented in the CLI reference (reconcilewas missing from it).Why
When an environment adopts the reconcile flow, its first desired-state file must match what already exists on the server. If it does not, the first apply makes unwanted changes. Writing that file by hand from list APIs is slow and easy to get wrong.
How
Exportis part of theReconcilercontract ininternal/reconcile: every kind must implement it, enforced at compile time. This follows rule 9 of RFC docs: RFC 0001 for declarative management of platform resources #1751.PlatformUserimplements it: one entry per principal and relation — a user or service user holding both admin and member exports as two entries. Users are referenced by email when they have one, service users by id. The bootstrap service account is skipped, the same as in reconcile.spec: [], which reconcile accepts as an intentional empty list.reconcileandexport.Guarantees covered by tests
reconcile --dry-runreports no changes, including principals that hold both relations.